package com.bignerdranch.android.technew;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class DrawerActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView textview;
    private ListView listview;
    private List<Bean> mBeanList;
    private DrawerLayout drawer;
    private Button btn;
    Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer);
        initView();
    }

    private void initView() {
        textview = (TextView) findViewById(R.id.textview);
        listview = (ListView) findViewById(R.id.listview);
        initData();
        listview.setAdapter(new ListViewAdapter(this, mBeanList));
        drawer = (DrawerLayout) findViewById(R.id.drawer);
        animation = AnimationUtils.loadAnimation(this,R.anim.alpha);

        drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                listview.setAnimation(animation);
                animation.start();
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                super.onDrawerStateChanged(newState);
            }
        });
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(this);
    }

    private void initData() {
        mBeanList = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            Bean bean = new Bean("Tecent" + i);
            mBeanList.add(bean);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn:
                drawer.openDrawer(Gravity.LEFT);
//                animation.start();

                break;
        }
    }
}
